/**
 * @file schedule_fun.h
 * @synopsis  通道调度函数接口的头文件
 * @author wen wjcapple@163.com
 * @version 2.0
 * @date 2016-06-28
 */
#ifndef _GLOBAL_H
#define  _GLOBALE_H
#include "assert.h"
#include "otdr_ch.h"
#include "tmsxx.h"
#include "program_run_log.h"
#ifdef __cplusplus
extern "C" {
#endif

#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)

//定义printf 显示文件名（不含路径），函数名，行，以及format指定的信息	
#define __DEBUG_1__  
#ifdef __DEBUG_1__  
#define PR_X(format,...) printf("File: %s, Fun %s, Line: %05d: "format"\n",__FILENAME__,__FUNCTION__, __LINE__, ##__VA_ARGS__)  
#else  
#define PR_X(formt,...)  
#endif

//定义编译屏障
#define barrier() __asm__ __volatile__("": : :"memory")

#define STR_LEN_IP 			16
//定义返回给网管的错误码
#define CMD_RET_OK			0 // 成功	
#define CMD_RET_NO_UNIT			1 // 业务单元不存在	
#define CMD_RET_COMMU_ERR		2 // 通信异常	
#define CMD_RET_CH_UNEXIST		3 //通道不存在
#define CMD_RET_TYPE_ERR		4 //单元类型错误
#define CMD_RET_PARA_INVLADE		5 //参数非法
#define CMD_RET_CANT_SAVE		6 //不能保存
#define CMD_RET_EXIST_CMD		7 //已存在一条命令
#define CMD_RET_MANAGER_EXIST		8 //节点管理器已存在
#define CMD_RET_TEST_ERROR		9 //测试异常
#define CMD_RET_NO_DATA			10 //FPGA通信异常
#define CMD_RET_SLOT_ERR		11 //FPGA通信异常
#define CMD_RET_OCVL_UP_CURV		12 //FPGA通信异常
#define CMD_RET_CMD_INVALDE		13 //FPGA通信异常
#define CMD_RET_CH_UNCFG		14 //FPGA通信异常
#define CMD_RET_TEST_TIME_OUT		15 //FPGA通信异常
#define CMD_RET_UPDATA_ERR		16 //FPGA通信异常
#define CMD_RET_OTHRER_ERROR 		0x80000036 	//其他错误码
//节点管理器地址，网管客户端地址，网管服务器	
#define ADDR_CU				0x0000000e
#define ADDR_HOST_NODE			0x0000001e
#define ADDR_HOST_CLIENT		0x0000002e
#define ADDR_HOST_SERVER		0x0000003e
//#define ADDR_LOCAL			0x6000000e
extern int32_t ADDR_LOCAL;		
//定义一些其他关键变量
#define MAX_RANG_M	1800000
#define OUTPUT_USR_MSG   1
//光纤告警级别	
#define FIBER_ALARM_LEV0	0
#define FIBER_ALARM_LEV1	1
#define FIBER_ALARM_LEV2	2
#define FIBER_ALARM_LEV3	3
#define SEC_NUM_IN_CH		10
//告警容错次数
#define ALARM_TRIGGER_NUM 	2
#define ALARM_FADE_NUM 		2
#define CH_MAX_TEST_NUM		3 
#define CH_MIN_TEST_NUM		2 
//通道的基数，从fpga中获取到，通道号+该基数为对外使用的通道号
//#define LOCAL_CARD_TYPE		1	 //8通道otdr
extern int32_t LOCAL_CARD_TYPE;			 //8通道otdr
extern volatile int32_t ch_offset; 
extern volatile int32_t card_slot; 
//通道的光纤段参数
extern struct _tagCHFiberSec *chFiberSec;
//定义otdr通道资源
extern struct _tagOtdrDev *otdrDev;
//spi设备
extern struct _tagSpiDev spiDev;
//用户点名测量
extern struct _tagUsrOtdrTest usrOtdrTest;
//通道状态
extern struct tms_cfgpip_status ch_state;
extern struct _tagDevMisc devMisc;
//调度任务信息
extern struct _tagThreadInfo tsk_schedule_info;
//otdr 算法线程
extern struct _tagThreadInfo tsk_otdr_info;
//otdr线程锁
extern pthread_mutex_t mutex_otdr;
//fpga信息
extern struct _tagCHInfo chFpgaInfo;
//算法线程计算时的通道信息
extern struct _tagAlgroCHInfo algroCHInfo;
//硬件软件版本号
extern struct _tagVersion DevVersion;
extern struct fpga_dev *fpga_device;
extern _tagSpiDevCtrl spi_ctrl; 
extern struct _tagOtdrTestCtrl otdrTestCtrl;
extern struct _tagGpioFd gpio_fd;
extern struct _tagThreadInfo tsk_debug_info;
extern struct _tagThreadInfo tsk_measur_info;
extern struct _tagThreadInfo tsk_service_info;
extern struct _tagCHAlarmDis chAlarmDis;
extern struct _tagThreadInfo tsk_connect_info;
extern struct fpga_info fpga_device_info;//fpga硬件设备信息
extern int32_t CH_NUM;
extern struct _tagThreadInfo *ptsk_testp_info;
extern struct _tagOtdrTestCtrl otdrTestCtrl;
extern struct _tagParalleCtrl *paralleCtrlBuf;
extern struct _tagUsrOtdrTest *usrOtdrTestBuf_P;
extern const float ALARM_SCALE;
extern int32_t GPIO_NUM_SLOT  ;
extern int32_t GPIO_NUM_CH_ALARM ;	
extern struct _tagTickCount TickCount;
#ifdef __cplusplus
}
#endif

#endif
